var arrUrl = ["/static/image/banner1.png", "/static/image/banner2.png", "/static/image/banner3.png","/static/image/banner4.png" ];
var curIndex = 0;
window.onload = function() {
	var oPrev = document.getElementById("prev");
	var oNext = document.getElementById("next");
	var oImg1 = document.getElementById("img");

	oImg1.src = arrUrl[curIndex];
	oNext.onclick = function() {
		curIndex++;
		if (curIndex == arrUrl.length) {
			curIndex = 0;
		}
		oImg1.src = arrUrl[curIndex];
	}
	oPrev.onclick = function() {
		curIndex--;
		if (curIndex == -1) {
			curIndex = arrUrl.length - 1;
		}
		oImg1.src = arrUrl[curIndex];
	}

	
	imgLen = arrUrl.length; // 图片总数
	// 定时器自动变换2.5秒每次
	var autoChangeAgain = setInterval(function() {
		if (curIndex < imgLen - 1) {
			curIndex++;
		} else {
			curIndex = 0;
		}
		// 调用变换处理函数
		changeTo(curIndex);
	}, 2500);
	var autoChange = setInterval(function() {
		if (curIndex < imgLen - 1) {
			curIndex++;
		} else {
			curIndex = 0;
		}
		// 调用变换处理函数
		changeTo(curIndex);
	}, 2500);
	function changeTo(num){ 
		oImg1.src = arrUrl[num];
	  }
	addEvent();
	function addEvent(){
	 // 给左箭头prev添加上一个事件
	  var prev = document.getElementById("prev");
	  prev.onmouseover = function(){ 
	    // 滑入清除定时器
	    clearInterval(autoChange);
	  };
	  

	prev.onclick = function(){ 
	    // 根据curIndex进行上一个图片处理
	    curIndex = (curIndex > 0) ? (--curIndex) : (imgLen - 1);
	    changeTo(curIndex);
	  };

	prev.onmouseout = function(){ 
	    // 滑出则重置定时器
	    autoChangeAgain();
	  };

	  // 给右箭头next添加下一个事件
	  var next = document.getElementById("next");
	  next.onmouseover = function(){ 
	    clearInterval(autoChange);
	  };
	  next.onclick = function(){ 
	    curIndex = (curIndex < imgLen - 1) ? (++curIndex) : 0;
	    changeTo(curIndex);
	  };
	  next.onmouseout = function(){ 
	    autoChangeAgain();
	  };

	  };
}